<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<div style="margin-top: 20px;">

    <div class="search_block">
        搜索：
        <div class="layui-inline">
            <input class="layui-input" name="s_name" id="s_name" placeholder="项名称" autocomplete="off">
        </div>
        <button class="layui-btn" id="search_btn" data-type="search">搜索</button>
        <label class="tip">${stateMsg}</label>
        <button class="layui-btn" style="float: right;padding-right: 10px" id="add_btn" data-type="add">添加新库存项</button>
    </div>

    <table class="layui-hide" id="storeItems_table" lay-filter="storeItems_table"></table>

    <%--操作条--%>
    <script type="text/html" id="tool_bar">
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">编辑</a>
    </script>


    <script>
        layui.use(['table','layer'], function(){
            var table = layui.table,layer=layui.layer,$=layui.jquery;
            table.render({
                elem: '#storeItems_table'
                ,url:'/back/storeitem/load'
                ,cols: [[
                    {field:'name', width:120, title: '入库项目名' ,sort: true}
                    ,{field:'warning',width:120,title:'预警值'}
                    ,{field:'unit',width:120,title:'单位'}
                    ,{fixed: 'right', align:'center', toolbar: '#tool_bar'}
                ]]
                ,done:function () {
                }
                ,id:'id'
                ,page: true
                ,limit:10
            });

            //操作按钮监听模块
            table.on('tool(storeItems_table)',function (obj) {
                var data=obj.data;
                var event=obj.event;
                if(event=='edit'){

                    layer.open({
                        title:'修改页面'
                        ,type: 1
                        ,skin: 'layui-layer-lan'
                        ,area: ['330px','320px']
                        , content: $('#storeItem_form')
                        ,success: function(layero, index){
                            $('#storeItem_form').attr('action','${pageContext.request.contextPath}/back/storeitem/modifyInfo');
                            $('#id').val(data.id);
                            $('#name').val(data.name);
                            $('#warning').val(data.warning);
                            $('#unit').val(data.unit);
                            $('#btn').text("提交修改");
                        }
                    });
                }
            });

            //搜索添加模块
            var $ = layui.$, active = {
                search: function(){
                    var s_name = $('#s_name').val();
                    table.reload('id', {
                        where: {
                            s_name:s_name
                        }
                        ,page: {
                            curr:1
                        }

                    });
                }
                ,add:function () {
                    layer.open({
                        title:'添加新入库项'
                        ,type: 1
                        ,skin: 'layui-layer-lan'
                        ,area: ['330px','320px']
                        , content: $('#storeItem_form')
                        ,success: function(layero, index){
                            $('#storeItem_form').attr('action','${pageContext.request.contextPath}/back/storeitem/add');
                            $('#name').val("");
                            $('#warning').val("");
                            $('#unit').val("");
                            $('#btn').text("提交添加");
                        }
                    })
                }
            };

            $('#search_btn').on('click', function(){
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });

            $('#add_btn').on('click', function(){
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });


        layui.use(['form', 'layedit'],function () {
            var form = layui.form;

            form.on('submit(check)', function(data){
                return true;
            });


        });
    </script>

</div>

<form id="storeItem_form" style="display: none" class="layui-form" action="#" method="post">
    <input type="hidden" id="id" name="id"/>
    <div class="info_form_body">
        <div class="layui-form-item">
            <label class="layui-form-label">入库项名称:</label>
            <div class="layui-input-block">
                <input id="name" type="text" name="name"  lay-verify="required" placeholder="入库项名称" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">预警值:</label>
            <div class="layui-input-block">
                <input id="warning" type="text" name="warning"  lay-verify="required|number" placeholder="预警值" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">单位:</label>
            <div class="layui-input-block">
                <input id="unit" type="text" name="unit"  lay-verify="required" placeholder="单位" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button id="btn" lay-submit="" lay-filter="check" class="layui-btn"></button>
            </div>
        </div>
    </div>
</form>